package com.jason.utils;

import java.awt.*;

/**
 * @Description 窗口工具
 * @Date 2020/10/12 11:49
 * @Author by 尘心
 */
public class WindowUtil {

    /**
     * 获取当前屏幕的尺寸
     */
    public static Dimension getScreenSize() {
        //定义工具包
        Toolkit kit = Toolkit.getDefaultToolkit();
        //获取屏幕的尺寸
        return kit.getScreenSize();
    }


    /**
     * 根据屏幕尺寸生成界面大小
     * @param dimension 屏幕尺寸
     * @param size      界面尺寸大小
     */
    public static Rectangle generateFrame(Dimension dimension,double size) {
        Rectangle frameRectangle = new Rectangle();
        if (dimension!=null) {
            double width = dimension.getWidth();
            double height = dimension.getHeight();

            // 生成界面的宽度
            int frameWidth = convert2Int(width*size);
            int frameHeight = convert2Int(height*size);

            int boundsX = convert2Int((width - frameWidth)/2);
            int boundsY = convert2Int((height - frameHeight)/2);

            frameRectangle.setBounds(boundsX,boundsY,frameWidth,frameHeight);
        }

        return frameRectangle;
    }

    /**
     * 获取字体
     */
    public static Font getFont() {
        return new Font("微软雅黑",Font.PLAIN,15);
    }


    /**
     * double --> int
     * @param value
     */
    private static int convert2Int(double value) {
        return (int) Math.round(value);
    }
}
